package com.bestcem.xm.user.service.impl;

import cn.hutool.core.lang.ObjectId;
import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.user.dao.UserUserAuthLogDao;
import com.bestcem.xm.user.service.UserUserAuthLogService;
import com.bestcem.xm.user.service.dto.user.UserAuthLogDTO;
import com.bestcem.xm.user.util.convert.UserAuthLogConvert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户操作日志
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/1 14:30
 */
@Slf4j
@Service
public class UserUserAuthLogServiceImpl implements UserUserAuthLogService {

    @Resource
    private UserAuthLogConvert userAuthLogConvert;

    @Autowired
    private UserUserAuthLogDao userUserAuthLogDao;

    @Override
    public ServiceResult<String> insert(UserAuthLogDTO dto) {
        // 校验参数
        if (dto == null || ObjectId.isValid(dto.getLogId())) {
            return ServiceResult.fail("参数为空或格式不正确");
        }

        // 新增
        String logId = userUserAuthLogDao.insert(userAuthLogConvert.dtoToDo(dto));
        dto.setLogId(logId);
        return ServiceResult.success(logId);
    }
}
